package com.love.rongapi.controller;

import com.love.rongapi.model.request.*;
import com.love.rongapi.model.response.UserResponse;
import com.love.rongapi.service.UserService;
import com.love.rongcommon.base.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@Api(tags = "用户中心")
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Resource
    private UserService userService;

    @ApiOperation("创建AccessToken")
    @GetMapping("/createAccessToken")
    public String createAccessToken(@Valid AccessTokenGetRequest request) {
        String accessToken = userService.createAccessToken(request);
        return accessToken;
    }

    @ApiOperation("添加用户")
    @PostMapping("/saveUser")
    public Boolean saveUser(@Valid UserSaveRequest request) {
        return userService.saveUser(request);
    }

    @ApiOperation("更新用户")
    @PostMapping("/updateUser")
    public Boolean updateUser(@Valid UserUpdateRequest request) {
        return userService.updateUser(request);
    }

    @ApiOperation("删除用户")
    @PostMapping("/deleteUser")
    public Boolean deleteUser(@Valid UserDeleteRequest request) {
        return userService.deleteUser(request);
    }

    @ApiOperation("获取用户信息")
    @GetMapping("/getUser")
    public UserResponse getUser(@Valid UserGetRequest request) {
        return userService.getUser(request);
    }
}
